﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HMIS.FrameWork.DomainBase;
using HMIS.FrameWork;
using Iesi.Collections.Generic;
using System.Web.Security;
using Newtonsoft.Json;
using System.Xml.Serialization;

namespace HMIS.Infrastructure.Core.Authority
{
	/// <summary>
	///  系统用户的基类
	/// </summary>
	[Serializable]
	public class Person : InputItem
	{
		private string loginName;
		private string pwd;		

		/// <summary>
		/// 登录名
		/// </summary>
		public virtual string LoginName
		{
			get 
			{
				return this.loginName;
			}
			set
			{ 
				if (String.IsNullOrEmpty(value))
					throw new NotNullException();
				this.loginName=value;
			}
		}

		/// <summary>
		/// 密码
		/// </summary>
		public virtual string Pwd
		{
			get
			{
				return this.pwd;
			}
			set
			{
				if (String.IsNullOrEmpty(value))
					throw new NotNullException();
				this.pwd = value;
			}

		}

		/// <summary>
		/// 手机号码
		/// </summary>
		public virtual string Mobitl { get; set; }

		/// <summary>
		/// 家庭电话
		/// </summary>
		public virtual string Hometl { get; set; }

		/// <summary>
		/// 办公电话
		/// </summary>
		public virtual string Offitl { get; set; }

		/// <summary>
		/// 短号
		/// </summary>
		public virtual string Shortl { get; set; }

		/// <summary>
		/// 所在机构编号
		/// </summary>
		public virtual string DepartmentId { get; set; }

		/// <summary>
		/// 所在机构
		/// </summary>
		public virtual Department Department { get; set; }

		/// <summary>
		/// 所属分组
		/// </summary>
		public virtual string UserGroup { get; set; }

		/// <summary>
		/// 职务
		/// </summary>
		public virtual string PostId {get; set;}
		
		/// <summary>
		/// 描述
		/// </summary>
		//public virtual string Description { get; set; }

		/// <summary>
		/// 用户状态
		/// </summary>
		public virtual PersonState State { get; set; }

		/// <summary>
		/// 用户所在角色
		/// <remarks>一个用户可能具有多个角色</remarks>
		/// </summary>
		[System.Xml.Serialization.XmlIgnore]
		public virtual Iesi.Collections.Generic.ISet<Role> Roles { get; set; }

		/// <summary>
		/// 用户常用菜单
		/// </summary>
		[System.Xml.Serialization.XmlIgnore]
		public virtual Iesi.Collections.Generic.ISet<MenuNode> FavoriteMenus { get; set; }

		/// <summary>
		/// 获取pwd参数的MD5编码
		/// </summary>
		/// <param name="pwd"></param>
		/// <returns></returns>
		public static string GetPwdMD5(string pwd)
		{	
			return FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
		}
	}

	/// <summary>
	/// 用户状态
	/// </summary>
	public enum PersonState
	{
		[EnumDescription("正常")]
		Normal=0,

		[EnumDescription("停用")]
		Disabled=1
	}
}
